package com.gxuwz.check.action.admin;

import com.alibaba.fastjson.JSONObject;
import com.gxuwz.check.base.BaseAction;
import com.gxuwz.check.model.dto.TeacherDto;
import com.gxuwz.check.model.entity.SysClassEntity;
import com.gxuwz.check.model.entity.SysTeacherEntity;
import com.gxuwz.check.service.admin.ITeacherAdminService;
import com.gxuwz.check.util.ResultJson;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class TeacherAdminAction extends BaseAction implements ModelDriven<SysTeacherEntity> {
    @Override
    public SysTeacherEntity getModel() {
        return null;
    }

    @Autowired
    private ITeacherAdminService teacherService;

    private int page;

    private Integer collegeId;

    private String teacherName;
    private Integer teacherSex;
    private String teacherTel;
    private String collegeIdAdd;
    private String classId;

    private Integer teacherId;
    /**
     * 获取所有老师
     */
    public void list() {
        List<TeacherDto> list = teacherService.list(page);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("list",list);
        ResultJson.R(jsonObject);
    }

    /**
     * 删除学生
     */
    public void delete() {
        teacherService.delete(teacherId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    /**
     * 修改学生
     */
    public void edit() {

    }

    /**
     * 添加学生
     */
    public void save() {
        teacherService.save(teacherName,teacherSex,teacherTel,collegeIdAdd,classId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    /**
     * 根据学院ID获取学院下的班级
     * @return
     */
    public void listClassByCollegeId(){
        List<SysClassEntity> list = teacherService.listClassByCollegeId(collegeId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("list",list);
        ResultJson.R(jsonObject);

    }

    /**
     * 根据老师ID获取老师信息
     * @return
     */
    public void findTeacherById(){
        SysTeacherEntity sysTeacherEntity = teacherService.findTeacherById(teacherId);
        System.out.println("sys---"+sysTeacherEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("info",sysTeacherEntity);
        ResultJson.R(jsonObject);
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public Integer getCollegeId() {
        return collegeId;
    }

    public void setCollegeId(Integer collegeId) {
        this.collegeId = collegeId;
    }

    public String getTeacherName() {
        return teacherName;
    }

    public void setTeacherName(String teacherName) {
        this.teacherName = teacherName;
    }

    public Integer getTeacherSex() {
        return teacherSex;
    }

    public void setTeacherSex(Integer teacherSex) {
        this.teacherSex = teacherSex;
    }

    public String getTeacherTel() {
        return teacherTel;
    }

    public void setTeacherTel(String teacherTel) {
        this.teacherTel = teacherTel;
    }

    public String getCollegeIdAdd() {
        return collegeIdAdd;
    }

    public void setCollegeIdAdd(String collegeIdAdd) {
        this.collegeIdAdd = collegeIdAdd;
    }

    public String getClassId() {
        return classId;
    }

    public void setClassId(String classId) {
        this.classId = classId;
    }

    public Integer getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(Integer teacherId) {
        this.teacherId = teacherId;
    }
}
